@extends('layout.member')

@section('body')
    <blockquote class="layui-elem-quote" style="margin: 1% 1%;">
        <span class="font-weight-bold careful">注意事项:</span><br><br>
        1.电话号码必须一次只能录入一个，不能复制多个添加；<br/>
        2.不能填写带有分机号的电话号码；<br/>
        3.不能出现双引号；<br/>
        4.电话号码中的横杠符号 “-”系统会自动剔除；<br/>
        5.不能按照规则录入将直接影响数据加工结果<br/>
    </blockquote>
    <div class="panel active">
        <div class="panel-head">
            <h4>添加物料号码</h4>
        </div>
        <div class="panel-body">
            <form class="layui-form layui-form-pane">
                @include('member.materiel.phone.body')
            </form>
        </div>
    </div>
@endsection
@section('js')
    <script type="text/javascript">
        layui.use(['form'], function () {
            var form = layui.form;
            //自定义验证规则
            form.verify({
                SPhone: function (value) {
                    if (checkTel(value) === false) {
                        return '坐席号码只能为手机号或者座机号';
                    }
                }
            });
            //监听提交
            form.on('submit(submitMaterielPhone)', function (data) {
                var param = data.field;
                $.post("{{route('materielPhone.store')}}",
                    {
                        _token: '{{csrf_token()}}',
                        param: param
                    },
                    function (data) {
                        if (data.status == 200) {
                            layer.msg(data.msg);
                            setTimeout(function () {
                                window.location.href = data.data;
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                        }
                    });
                return false;
            });
        });
        function checkTel(tel) {
            var mobile = /^(13[0-9]|14[5|7|9]|15[0|1|2|3|5|6|7|8|9]|16[6]|17[0|1|2|3|5|6|7|8]|18[0-9]|19[8|9])\d{8}$/,
                phone = /^0\d{2,3}-?\d{7,8}$/;
            return mobile.test(tel) || phone.test(tel);
        }
    </script>
@append